home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Dialog Boxes / SimplerDialog / SimplerDialog.cs next >
Encoding:
Text File  |  2001-01-15  |  2.0 KB  |  70 lines

  1. //--------------------------------------------
  2. // SimplerDialog.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SimplerDialog: Form
  9. {
  10.      string strDisplay = "";
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new SimplerDialog());
  15.      }
  16.      public SimplerDialog()
  17.      {
  18.           Text = "Simpler Dialog";
  19.  
  20.           Menu = new MainMenu();
  21.           Menu.MenuItems.Add("&Dialog!", new EventHandler(MenuOnClick));
  22.      }
  23.      void MenuOnClick(object obj, EventArgs ea)
  24.      {
  25.           SimplerDialogBox dlg = new SimplerDialogBox();
  26.           DialogResult     dr  = dlg.ShowDialog();
  27.  
  28.           strDisplay = "Dialog box terminated with " + dr + "!";
  29.           Invalidate();
  30.      }
  31.      protected override void OnPaint(PaintEventArgs pea)
  32.      {
  33.           Graphics grfx = pea.Graphics;
  34.           grfx.DrawString(strDisplay, Font, new SolidBrush(ForeColor), 0, 0);
  35.      }
  36. }
  37. class SimplerDialogBox: Form
  38. {
  39.      public SimplerDialogBox()
  40.      {
  41.           Text = "Simpler Dialog Box";
  42.  
  43.                // Standard stuff for dialog boxes
  44.  
  45.           FormBorderStyle = FormBorderStyle.FixedDialog;
  46.           ControlBox      = false;
  47.           MaximizeBox     = false;
  48.           MinimizeBox     = false;
  49.           ShowInTaskbar   = false;
  50.  
  51.                // Create OK button.
  52.  
  53.           Button btn = new Button();
  54.           btn.Parent   = this;
  55.           btn.Text     = "OK";
  56.           btn.Location = new Point(50, 50);
  57.           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);
  58.           btn.DialogResult = DialogResult.OK;
  59.  
  60.                // Create Cancel button.
  61.  
  62.           btn = new Button();
  63.           btn.Parent   = this;
  64.           btn.Text     = "Cancel";
  65.           btn.Location = new Point(50, 100);
  66.           btn.Size     = new Size (10 * Font.Height, 2 * Font.Height);
  67.           btn.DialogResult = DialogResult.Cancel;
  68.      }
  69. }
  70.